/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Reportes;

import Complementos.Validar;
import Control.ControlReporte;
import Control.ControlUbigeo;
import Util.Grafico;
import Util.Reporte;
import java.awt.Image;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane;

/**
 *
 * @author COMPUTER
 */
public final class ReporteGrafico extends javax.swing.JFrame {

    private Image imagen;
    Validar validar = new Validar();

    public void setImagen(Image imagen) {
        this.imagen = imagen;
    }

    /**
     * Creates new form ReporteGrafico
     */
    public ReporteGrafico() {
        initComponents();
        cargarComboDeptos();
        comboDepto.setSelectedItem("LIMA");
        habilitarUbigeo(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupTipoReporte = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        cbxtipo = new javax.swing.JComboBox();
        lbldesde = new javax.swing.JLabel();
        lblhasta = new javax.swing.JLabel();
        lblFecha = new javax.swing.JLabel();
        panGrafico = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        lblTodo = new javax.swing.JLabel();
        rbnFecha = new javax.swing.JRadioButton();
        rbnTodo = new javax.swing.JRadioButton();
        btnExportar = new javax.swing.JButton();
        chooserDesde = new datechooser.beans.DateChooserCombo();
        chooserHasta = new datechooser.beans.DateChooserCombo();
        comboDepto = new javax.swing.JComboBox();
        comboProvincia = new javax.swing.JComboBox();
        comboDistrito = new javax.swing.JComboBox();
        lbldepto = new javax.swing.JLabel();
        lblprov = new javax.swing.JLabel();
        lbldist = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cbxMes = new javax.swing.JComboBox();
        lblMes = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("RICOS REPORTES - AHHHH");

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Reportes", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tunga", 0, 24), new java.awt.Color(255, 255, 153))); // NOI18N

        jLabel1.setText("TIPO DE REPORTE");

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/grafico.gif"))); // NOI18N
        jButton1.setText("Graficar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        cbxtipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Pacientes por Genero", "Pacientes por Distrito", "Odontologos mas solicitados", " " }));
        cbxtipo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbxtipoItemStateChanged(evt);
            }
        });

        lbldesde.setText("DESDE:");

        lblhasta.setText("HASTA:");

        lblFecha.setText("POR FECHA");

        panGrafico.setBackground(new java.awt.Color(255, 255, 255));
        panGrafico.setRequestFocusEnabled(false);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(204, 204, 204));
        jLabel2.setText("Reporte Gráfico");

        javax.swing.GroupLayout panGraficoLayout = new javax.swing.GroupLayout(panGrafico);
        panGrafico.setLayout(panGraficoLayout);
        panGraficoLayout.setHorizontalGroup(
            panGraficoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panGraficoLayout.createSequentialGroup()
                .addContainerGap(142, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(136, 136, 136))
        );
        panGraficoLayout.setVerticalGroup(
            panGraficoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panGraficoLayout.createSequentialGroup()
                .addGap(127, 127, 127)
                .addComponent(jLabel2)
                .addContainerGap(140, Short.MAX_VALUE))
        );

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/1leftarrow.png"))); // NOI18N
        jButton2.setText("Salir");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        lblTodo.setText("TODO");

        rbnFecha.setBackground(new java.awt.Color(255, 255, 255));
        groupTipoReporte.add(rbnFecha);
        rbnFecha.setSelected(true);
        rbnFecha.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        rbnFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbnFechaActionPerformed(evt);
            }
        });

        groupTipoReporte.add(rbnTodo);
        rbnTodo.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        rbnTodo.setDoubleBuffered(true);
        rbnTodo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                rbnTodoItemStateChanged(evt);
            }
        });

        btnExportar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/xpdf.jpg"))); // NOI18N
        btnExportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportarActionPerformed(evt);
            }
        });

        chooserDesde.setCurrentView(new datechooser.view.appearance.AppearancesList("Grey",
            new datechooser.view.appearance.ViewAppearance("custom",
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    true,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 255),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(128, 128, 128),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(255, 0, 0),
                    false,
                    false,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                (datechooser.view.BackRenderer)null,
                false,
                true)));
    chooserDesde.setLocale(new java.util.Locale("es", "PE", ""));

    chooserHasta.setCurrentView(new datechooser.view.appearance.AppearancesList("Grey",
        new datechooser.view.appearance.ViewAppearance("custom",
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.ButtonPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(0, 0, 255),
                true,
                true,
                new datechooser.view.appearance.swing.ButtonPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 255),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.ButtonPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(128, 128, 128),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.LabelPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.LabelPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(255, 0, 0),
                false,
                false,
                new datechooser.view.appearance.swing.ButtonPainter()),
            (datechooser.view.BackRenderer)null,
            false,
            true)));
chooserHasta.setLocale(new java.util.Locale("es", "PE", ""));

comboDepto.setEnabled(false);
comboDepto.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(java.awt.event.ItemEvent evt) {
        comboDeptoItemStateChanged(evt);
    }
    });

    comboProvincia.setEnabled(false);
    comboProvincia.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            comboProvinciaItemStateChanged(evt);
        }
    });

    comboDistrito.setEnabled(false);

    lbldepto.setText("Depatamento:");
    lbldepto.setEnabled(false);

    lblprov.setText("Provincia:");
    lblprov.setEnabled(false);

    lbldist.setText("Distrito:");
    lbldist.setEnabled(false);

    jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/CMIM.png"))); // NOI18N
    jLabel5.setText("jLabel5");

    cbxMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));
    cbxMes.setEnabled(false);

    lblMes.setText("Mes:");
    lblMes.setEnabled(false);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(46, 46, 46)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(panGrafico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(36, 36, 36)))
                    .addGap(43, 43, 43))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblFecha)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblhasta)
                            .addComponent(lbldesde)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(rbnFecha)
                            .addGap(27, 27, 27)
                            .addComponent(lblTodo)
                            .addGap(18, 18, 18)
                            .addComponent(rbnTodo))
                        .addComponent(chooserDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(chooserHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cbxtipo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblMes, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbldepto, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblprov, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addComponent(lbldist, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(comboDepto, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cbxMes, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(comboDistrito, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(btnExportar, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(81, 81, 81))))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(cbxtipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(rbnFecha)
                        .addComponent(lblTodo)
                        .addComponent(lblFecha)
                        .addComponent(rbnTodo))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(lbldesde)
                        .addComponent(chooserDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(lblhasta)
                        .addComponent(chooserHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(18, 18, 18)
                    .addComponent(btnExportar))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cbxMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblMes))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(comboDepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbldepto))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(comboProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblprov))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(comboDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbldist))))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                    .addGap(34, 34, 34)
                    .addComponent(panGrafico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                    .addGap(42, 42, 42)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(29, 29, 29)
                    .addComponent(jButton2)))
            .addContainerGap(23, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int opcion = -1;
        opcion = cbxtipo.getSelectedIndex();
        System.out.println(opcion);
        if (opcion != 0) {
            switch (opcion) {
                case 1:
                    if (rbnFecha.isSelected()) {
                        reportePorGeneroyFecha();
                    } else if (rbnTodo.isSelected()) {
                        reportePorGeneroTodo();
                    }
                    break;
                case 2:
                    if (rbnFecha.isSelected()) {
                        reportePorUbigeoyFecha();
                    } else if (rbnTodo.isSelected()) {
                        reportePorUbigeoTodo();
                    }
                    break;
                case 3: reporteOdontologoSolicitadoPorMes(); break;
                case 4: reporteReservasPorTratamientoyMes(); break;
                case 5: reporteCitasDeOdontologosPorFecha(); break;   
                case 6: reporteReservaCanceladaPorFecha();   break;   
                case 7: reporteIngresoPorMes();             break; 
                case 8: reporteIngresoMensuales();           break;  
                case 9: reporteOdontologoPorFecha();         break;   
                case 10: reporteTratamientoMesJunio();       break;   
                //case 11: reporteOdontologoSolicitadoPorMes(); break; 
                    //Probando para ricooo
                    
            }


        } else {
            JOptionPane.showMessageDialog(this, "Seleccione un tipo de reporte");
        }


    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void btnExportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarActionPerformed
        InputStream reporte = ReporteGrafico.class.getResourceAsStream("/graficos/PacienteGenero.jasper");
        ControlReporte controlR = new ControlReporte();
        Map parametros = new HashMap();
        try {
            List<Map<String, Object>> grafico1 = controlR.traerPacientePorGenero();
            // Image imagen = Grafico.crearBar(grafico1, "Pacientes por Genero", "Genero", "Cantidad", 531, 306);
            parametros.put("USUARIO", "MUSTTO_DIEGO");
            parametros.put("GRAFICO", imagen);


            Reporte.vistaPantallaEscritorio(reporte, grafico1, parametros);
        } catch (Exception ex) {
            System.out.println("ERROR : " + ex.getMessage());
        }


    }//GEN-LAST:event_btnExportarActionPerformed

    private void comboDeptoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboDeptoItemStateChanged
        comboProvincia.removeAllItems();
        int cod = comboDepto.getSelectedIndex();
        cargarComboProvincias(cod);
    }//GEN-LAST:event_comboDeptoItemStateChanged

    private void comboProvinciaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboProvinciaItemStateChanged
        comboDistrito.removeAllItems();
        int codD = comboDepto.getSelectedIndex();
        int codP = comboProvincia.getSelectedIndex();
        cargarComboDistritos(codD, codP);
    }//GEN-LAST:event_comboProvinciaItemStateChanged

    private void cbxtipoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxtipoItemStateChanged
        boolean xvalor = false, yvalor = false, zvalor = false;
        switch (cbxtipo.getSelectedIndex()) {
            case 1:xvalor = true; zvalor = true; break;
            case 2:xvalor = true; zvalor = true; break;
            case 3:yvalor = true; break;
            case 4:yvalor = true; break;
            case 5:zvalor = true; break;
            case 6:zvalor = true; break;
            case 7:yvalor = true; break; 
            case 9:xvalor = true; zvalor = true; break; 
            case 10:yvalor= true; break;    
                
        }
        
        
        habilitarUbigeo(xvalor);
        habilitarMes(yvalor);
        habilitarChooser(xvalor);
        habilitarRadioButtons(xvalor);
        habilitarChooser(zvalor);
    }//GEN-LAST:event_cbxtipoItemStateChanged

    private void rbnTodoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbnTodoItemStateChanged
        if (cbxtipo.getSelectedIndex() != 0) {
            if (rbnTodo.isSelected()) {
                habilitarUbigeo(false);
            } else {
                habilitarUbigeo(true);
            }

        } else {
            JOptionPane.showMessageDialog(this, "Seleccione Tipo de Reporte");
        }
    }//GEN-LAST:event_rbnTodoItemStateChanged

    private void rbnFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbnFechaActionPerformed
        if (cbxtipo.getSelectedIndex() != 0) {

            if (!rbnFecha.isSelected()) {
                habilitarUbigeo(false);
            }

        } else {
            JOptionPane.showMessageDialog(this, "Seleccione Tipo de Reporte");
        }
    }//GEN-LAST:event_rbnFechaActionPerformed

    
    
    public void reporteTratamientoMesJunio(){
     int opcionmes = cbxMes.getSelectedIndex();
        String nombre = cbxMes.getSelectedItem().toString();
        ControlReporte reporte = new ControlReporte();
        List<Map<String, Object>> grafico = reporte.reporteTratamientoMesJunio(opcionmes);
        Image imagen = Grafico.crearBar(grafico, "Reservas por tratamiento de " + nombre, "Tratamiento", "Reservas", 531, 306);
        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);
    
    }
    
    
    
    
    public void reporteOdontologoPorFecha(){
        ControlReporte reporte = new ControlReporte();
        ControlUbigeo controlUbi = new ControlUbigeo();
        int idubigeo = controlUbi.dameIdUbigeo(comboDepto.getSelectedIndex() + 1, comboProvincia.getSelectedIndex() + 1, comboDistrito.getSelectedIndex() + 1);
       
       String fechainicio = validar.cambiarFormatoFechaParaBD(chooserDesde.getText());
       String fechafin = validar.cambiarFormatoFechaParaBD(chooserHasta.getText());
       
       List<Map<String, Object>> grafico = reporte.reporteOdontologoPorFecha(fechainicio, fechafin, idubigeo);
//       for (Map xgrafico : grafico) {
//            System.out.println(xgrafico.get("name") + " - "+
//                     xgrafico.get("total"));
//        } 
       Image imagen = Grafico.crearBar(grafico, " Reservas De Odontologos por Fecha \n desde  " + chooserDesde.getText() +" hasta "+ chooserHasta.getText(), "name", "total", 531, 306);
       setImagen(imagen);
       this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);
    
    }
    
    
    
    
    public void reporteIngresoMensuales(){
    
       ControlReporte reporte = new ControlReporte();
       List<Map<String, Object>> grafico = reporte.reporteIngresoMensuales();
       Image imagen = Grafico.crearBar(grafico, "Reporte de Ingreso de Todos los MESES","Mes", "Montos", 531, 306);
       setImagen(imagen);
       this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);     
    
    }
    
    
    public void reporteIngresoPorMes(){
       int opcionmes = cbxMes.getSelectedIndex();
       String nombre = cbxMes.getSelectedItem().toString();
       ControlReporte reporte = new ControlReporte();
       List<Map<String, Object>> grafico = reporte.reporteIngresoPorMes(opcionmes);
       Image imagen = Grafico.crearBar(grafico,"Ingreso del Mes" , "Mes", "Ingreso", 531, 306);
       setImagen(imagen);
       this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);    
    
    }
    
    
    
    public void reporteReservaCanceladaPorFecha(){
       String fechainicio = validar.cambiarFormatoFechaParaBD(chooserDesde.getText());
       String fechafin = validar.cambiarFormatoFechaParaBD(chooserHasta.getText());
       ControlReporte reporte = new ControlReporte();
       List<Map<String, Object>> grafico = reporte.reporteReservaCanceladaPorFecha(fechainicio, fechafin);
      
       Image imagen = Grafico.crearBar(grafico, " Reservas canceladas por Tratamiento \n desde  " + chooserDesde.getText() +" hasta "+ chooserHasta.getText(), "Tratamiento", "Cantidad", 531, 306);
       setImagen(imagen);
       this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);      
    }
    
    public void reporteCitasDeOdontologosPorFecha(){
        String fechainicio = validar.cambiarFormatoFechaParaBD(chooserDesde.getText());
        String fechafin = validar.cambiarFormatoFechaParaBD(chooserHasta.getText());
//        System.out.println("inicio "+fechainicio);
//        System.out.println("fin "+fechafin);
        ControlReporte reporte = new ControlReporte();
        List<Map<String, Object>> grafico = reporte.reporteCitasDeOdontologosPorFecha(fechainicio, fechafin);
        Image imagen = Grafico.crearBar(grafico, " Reservas por Odontologo \n desde  " + chooserDesde.getText() +" hasta "+ chooserHasta.getText(), "Odontologo", "Citas", 531, 306);
        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);
    
    }
    
    
    public void reporteReservasPorTratamientoyMes() {
        int opcionmes = cbxMes.getSelectedIndex();
        String nombre = cbxMes.getSelectedItem().toString();
        ControlReporte reporte = new ControlReporte();
        List<Map<String, Object>> grafico = reporte.reporteReservasPorTratamientoyMes(opcionmes);
        Image imagen = Grafico.crearTorta(grafico, "Reservas por tratamiento de " + nombre, "Reservas", "Tratamiento", 531, 306);
        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);
    }

    public void reporteOdontologoSolicitadoPorMes() {
        int opcionmes = cbxMes.getSelectedIndex();
        String nombre = cbxMes.getSelectedItem().toString();
        // Creamos un objeto del controlador en este caso de ControlReporte
        ControlReporte reporte = new ControlReporte();
        //Miguel - 50
        //Diego  - 40
        //Stefanie - 30
        //Object puede ser int, double, etc....
        List<Map<String, Object>> grafico = reporte.reporteOdontologoSolicitadoPorMes(opcionmes);
//        Recorrido de "grafico" con un for para ver lo que trae de la base de datos
//        for (Map xgrafico : grafico) {
//            System.out.println(xgrafico.get("Odontologo") + " - "+
//                     xgrafico.get("Citas"));
//        }
        Image imagen = Grafico.crearBar(grafico, "Odontólogos más Solicitados de " + nombre, "Odontologo", "Citas", 531, 306);
        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);

    }

    public void reportePorUbigeoTodo() {
        int imprime = 0;
        ControlReporte reporte = new ControlReporte();

        List<Map<String, Object>> grafico = reporte.traerPacientePolimorfismoFechaUbigeo();

        Image imagen = Grafico.crearBar(grafico, "Pacientes Por Distrito", "Ubicacion", "Cantidad", 531, 306);
        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);

    }

    public void reportePorUbigeoyFecha() {
        int imprime = 0;
        ControlReporte reporte = new ControlReporte();
        ControlUbigeo controlUbi = new ControlUbigeo();
        int idubigeo = controlUbi.dameIdUbigeo(comboDepto.getSelectedIndex() + 1, comboProvincia.getSelectedIndex() + 1, comboDistrito.getSelectedIndex() + 1);
        System.out.println(idubigeo);
        String fechainicio = validar.cambiarFormatoFechaParaBD(chooserDesde.getText());
        String fechafin = validar.cambiarFormatoFechaParaBD(chooserHasta.getText());
        List<Map<String, Object>> grafico = reporte.traerPacientePolimorfismoFechaUbigeo(fechainicio, fechafin, idubigeo);
        for (Map xgrafico : grafico) {
            imprime = Integer.parseInt(xgrafico.get("Cantidad").toString());
        }
        if (imprime != 0) {
            Image imagen = Grafico.crearBar(grafico, "Pacientes Por Distrito", "Ubicacion", "Cantidad", 523, 311);
            setImagen(imagen);
            this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);
        } else {
            JOptionPane.showMessageDialog(this, "No hay pacientes registrados es las fechas indicadas", "Mensaje :::: SONRISAS TOOLS", JOptionPane.INFORMATION_MESSAGE);

        }
    }

    public void reportePorGeneroTodo() {
        ControlReporte reporte = new ControlReporte();
        List<Map<String, Object>> grafico = reporte.traerPacientePorGenero();
        Image imagen = Grafico.crearBar(grafico, "Pacientes por Genero", "Genero", "Cantidad", 523, 311);

        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);
//        Este codigo solo es para probar los datos que trae reporte.traerPacientePorGeneroTodo()          
//        for (Map xgrafico : grafico) {
//            System.out.println(xgrafico.get("Genero"));
//                    + xgrafico.get("Mujeres"));
//        }

    }

    public void reportePorGeneroyFecha() {
        System.out.println("entro");
        ControlReporte reporte = new ControlReporte();
        String fechainicio = validar.cambiarFormatoFechaParaBD(chooserDesde.getText());
        String fechafin = validar.cambiarFormatoFechaParaBD(chooserHasta.getText());

        List<Map<String, Object>> grafico = reporte.traerPacientePorGenero(fechainicio, fechafin);

        Image imagen = Grafico.crearBar(grafico, "Pacientes por Genero", "Hombres", "Mujeres", 531, 306);

        setImagen(imagen);
        this.panGrafico.getGraphics().drawImage(imagen, 0, 0, null);

//        probando que recoge texto de fecha correcto        
//        System.out.println("Inicio " + fechainicio);
//        System.out.println("Fin" + fechafin);
//        Este codigo solo es para probar los datos que trae reporte.traerPacientePorGeneroTodo()         
//        for (Map xgrafico : grafico) {
//            System.out.println(xgrafico.get("Hombres") + " - "
//                    + xgrafico.get("Mujeres"));
//        }
    }

    public final void cargarComboDeptos() {
        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listado = control.listarDeptos();

        for (int i = 0; i < listado.size(); i++) {
            comboDepto.addItem(listado.get(i).get(1).toString());
        }
    }

    public void cargarComboProvincias(int cod) {

        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listado = control.listarProvincias(cod + 1);

        for (int i = 0; i < listado.size(); i++) {
            comboProvincia.addItem(listado.get(i).get(0).toString());


        }
    }

    public void cargarComboDistritos(int codDepto, int codProv) {
        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listado = control.listarDistritos(codDepto + 1, codProv + 1);

        for (int i = 0; i < listado.size(); i++) {
            comboDistrito.addItem(listado.get(i).get(0).toString());
        }
    }

    public void habilitarUbigeo(boolean xvalor) {
        lbldepto.setEnabled(xvalor);
        lblprov.setEnabled(xvalor);
        lbldist.setEnabled(xvalor);
        comboProvincia.setEnabled(xvalor);
        comboDistrito.setEnabled(xvalor);
        comboDepto.setEnabled(xvalor);
    }

    public void habilitarMes(boolean xvalor) {
        lblMes.setEnabled(xvalor);
        cbxMes.setEnabled(xvalor);
    }

    public void habilitarRadioButtons(boolean xvalor) {
        lblFecha.setEnabled(xvalor);
        lblTodo.setEnabled(xvalor);
        rbnFecha.setEnabled(xvalor);
        rbnTodo.setEnabled(xvalor);
    }

    public void habilitarChooser(boolean xvalor) {
        lblFecha.setEnabled(xvalor);
        rbnFecha.setEnabled(xvalor);
        lbldesde.setEnabled(xvalor);
        lblhasta.setEnabled(xvalor);
        chooserDesde.setEnabled(xvalor);
        chooserHasta.setEnabled(xvalor);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ReporteGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ReporteGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ReporteGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ReporteGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ReporteGrafico().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExportar;
    private javax.swing.JComboBox cbxMes;
    private javax.swing.JComboBox cbxtipo;
    private datechooser.beans.DateChooserCombo chooserDesde;
    private datechooser.beans.DateChooserCombo chooserHasta;
    private javax.swing.JComboBox comboDepto;
    private javax.swing.JComboBox comboDistrito;
    private javax.swing.JComboBox comboProvincia;
    private javax.swing.ButtonGroup groupTipoReporte;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JLabel lblMes;
    private javax.swing.JLabel lblTodo;
    private javax.swing.JLabel lbldepto;
    private javax.swing.JLabel lbldesde;
    private javax.swing.JLabel lbldist;
    private javax.swing.JLabel lblhasta;
    private javax.swing.JLabel lblprov;
    private javax.swing.JPanel panGrafico;
    private javax.swing.JRadioButton rbnFecha;
    private javax.swing.JRadioButton rbnTodo;
    // End of variables declaration//GEN-END:variables
}
